package com.itheima.core.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.itheima.common.dto.PageRequestDto;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.expression.spel.ast.NullLiteral;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.Serializable;
import java.util.List;

public abstract class AbstractCoreController<T> implements ICoreController<T>{
    protected IService<T> service;
    public AbstractCoreController(IService<T> service){
        this.service=service;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @Override
    @DeleteMapping("del/{id}")
    @ApiOperation("通过id删除")
    public ResultVo delete(@PathVariable Serializable id) {
        if (service.removeById(id)){
        return ResultVo.ok();
        }
        return ResultVo.error();
    }

    /**
     * 添加
     *
     * @param record
     * @return
     */
    @Override
    @PostMapping
    public ResultVo save(@RequestBody T record) {
        if(service.save(record)){
        return ResultVo.ok();
        }
        return ResultVo.error();
    }

    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public PageResultVo page(PageRequestDto dto) {
        return null;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @Override
    public ResultVo<T> findById(Integer id) {
        return null;
    }

    /**
     * 查找所有
     *
     * @return
     */
    @Override
    public ResultVo<List<T>> findAll() {
        return null;
    }

    /**
     * 条件查询
     *
     * @param record
     * @return
     */
    @Override
    public ResultVo<List<T>> findByRecord(T record) {
        return null;
    }

    /**
     * 更新
     *
     * @param record
     * @return
     */
    @Override
    public ResultVo updateById(T record) {
        return null;
    }
}
